﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using AddIn.EA.Architecture.ExternalResources;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace AddIn.EA.Architecture.ComponentLogic
{
    public class RuleSetList : List<RuleSet>
    {
        private RuleSetList() { }

        public static RuleSetList LoadRuleSets()
        {
            XmlDocument xml = ExternalResources.RuleSet.GetRuleSetXml();

            RuleSetList list = new RuleSetList();

            foreach (XmlElement element in xml.DocumentElement.ChildNodes)
            {
                RuleSet ruleSet = new RuleSet();
                ruleSet.Name = element["Name"].InnerText;
                ruleSet.Parameters = new List<RuleSetParameter>();

                foreach (XmlElement elemParameter in element["Parameters"].ChildNodes)
                {
                    RuleSetParameter parameter = new RuleSetParameter();
                    parameter.Name = elemParameter["Name"].InnerText;
                    parameter.Type = (RuleSetParameterType)System.Enum.Parse(typeof(RuleSetParameterType), elemParameter["Type"].InnerText);
                    parameter.IsRequired = Convert.ToBoolean(elemParameter["IsRequired"].InnerText);

                    ruleSet.Parameters.Add(parameter);
                }

                list.Add(ruleSet);
            }

            return list;
        }
    }

    [Serializable()]
    public class RuleSet : ISerializable
    {
        #region Property
        [XmlElement("Name")]
        public string Name { get; set; }
        [XmlElement("Parameters")]
        public List<RuleSetParameter> Parameters { get; set; }
        #endregion

        #region ISerializable Members

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
